<template>
  <div>
    <header class="site-header jumbotron">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h1>请发表对Vue的评论</h1>
          </div>
        </div>
      </div>
    </header>
    <div class="container">
      <Add :addComment="addComment"/>
      <list :comments="comments" :deleteComment="deleteComment"/>
      <!-- 主键通讯-->
    </div>
  </div>
</template>

<script>
import Add from "./components/Add.vue";
import list from "./components/list.vue";
export default {
  data() {
    return {
      //数据在那个组件，更新数据的行为就应该定义在哪个主键
      comments: [
        {
          name: "ahai",
          content: "vue我觉得不行"
        },
        {
          name: "BOB",
          content: "vue我觉得还行"
        },
        {
          name: "test",
          content: "vue我觉得一般"
        }
      ]
    };
  },
  methods: {
    //添加评论
    addComment(comment) {
      this.comments.unshift(comment);
    },
    //删除指定下标评论
    deleteComment(index) {
      this.comments.splice(index, 1);
    }
  },
  components: {
    Add,
    list
  }
};
</script>


<style>
</style>
